<template>
  <el-dialog
    :visible.sync="$attrs.visableIf"
    @close="handleCloseDialog"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    width="880px"
  >
    <template slot="title">
      <span>方案名称：{{ row.title || "--" }}</span>
      <span class="f-12 c_text3">最后修改时间：2024-04-10 10:00</span>
    </template>
    <!--  -->
    <div class="flexbetween mb-16">
      <div>本方案已应用至下列企微号</div>
      <el-dropdown @command="handleCommand">
        <el-button size="small" type="primary" plain :disabled="multiple"
          >批量操作</el-button
        >
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">批量取消应用</el-dropdown-item>
          <el-dropdown-item command="b">批量开启</el-dropdown-item>
          <el-dropdown-item command="c">批量关闭</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <!-- <el-button size="small" type="primary" plain :disabled="multiple">批量操作</el-button> -->
    </div>
    <el-table
      v-loading="loading"
      :data="tableList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="80" fixed align="center" />
      <el-table-column
        label="企微号"
        fixed
        prop="userName"
        width="280"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div class="flex kh_box">
            <img
              src="//qyb-1253970052.cos.ap-shanghai.myqcloud.com/public/wechatdata/avatar/5424982/e9564f7860994fe258a93da3a18c1a2c.png"
              alt=""
              class="useravatar"
            />
            <div class="khnamebox pl-12">
              <div class="title c_222333">{{ scope.row.title }}</div>
              <div class="c_f08b00 f-12">@志新</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="最后应用时间"
        prop="time"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="方案状态	"
        prop="nickName"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button type="text" @click="handleCancle(scope.row)"
            >取消应用</el-button
          >
        </template>
      </el-table-column>
      <template slot="empty">
        <TableEmpty />
      </template>
    </el-table>
    <pagination
      class="mt-0"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
export default {
  name: "editName",
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        numberstr: "",
      },
      total: 0,
      tableList: [{ id: 1, title: "肖洁" }],
      loading: false,
      multipleSelection: [], //表格多选
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    };
  },
  props: {
    row: {
      type: Object,
      default: null,
    },
  },
  created() {},
  mounted() {},
  watch: {},
  methods: {
    getList() {},

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.multipleSelection = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    // 角色状态修改
    handleStatusChange(row) {
      let params = {}
      if(row){
        params.id = row.id
      }else{
        params.id = this.multipleSelection
      }
      changeRoleStatus(params).then(res=>{
        this.$modal.msgSuccess("操作成功");
      }).catch(()=>{
        if(row)
          row.status = row.status === "0" ? "1" : "0";
      })
      // let text = row.status === "0" ? "启用" : "停用";
      // this.$modal
      //   .confirm('确认要"' + text + '""' + row.roleName + '"角色吗？')
      //   .then(function () {
      //     return changeRoleStatus(row.roleId, row.status);
      //   })
      //   .then(() => {
      //     this.$modal.msgSuccess(text + "成功");
      //   })
      //   .catch(function () {
      //     row.status = row.status === "0" ? "1" : "0";
      //   });
    },

    handleCommand(type) {
      switch (type) {
        case "a":
          this.handleCancle()
          break;
        case "b":
          this.handleStatusChange()
          break;
        case "c":
          this.handleStatusChange()
          break;
        default:
          break;
      }
    },

    handleCancle(row) {
      this.$msgBox
        .showMsgBox({
          title: "删除选中企微号下的该方案，请确认。",
          content: "",
        })
        .then(() => {
          this.$message.success('删除成功')
          this.getList()
        })
        .catch(() => {});
    },

    onSubmit(formName) {
      //提交的代码
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log("提交表单");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleCloseDialog() {
      this.$emit("update:visableIf", false);
      this.$emit("handleQuery");
    },
  },
};
</script>

<style scoped lang="scss">
</style>
